package com.nf.health.app.activity.manage_health;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.activity.global.RegisterNickActivity;
import com.nf.health.app.activity.manage_health.bean.SugarEvent;
import com.nf.health.app.activity.manage_health.bean.UserKeyti;
import com.nf.health.app.core.MyGsonBuilder;
import com.nf.health.app.customview.WheelView;
import com.nf.health.app.datamain.activity.BloodPressureActivity;
import com.nf.health.app.datamain.activity.BloodSugarDataActivity;
import com.nf.health.app.homepage.activity.EvaluationActivity;
import com.nf.health.app.http.Act;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.TextUtilTools;
import com.nf.health.app.utils.Util;
import com.nf.health.app.widget.KetiSignUpSuccessDialog;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.qqtheme.framework.picker.DatePicker;

/**
 * 高血压/糖尿病 智慧防控计划
 *
 * @Auther changpeng
 */
public class PreventionBloodPressureActivity extends BaseActivity {

    @Bind(R.id.et_name)
    EditText mEtName;
    @Bind(R.id.tv_birthday)
    TextView mTvBirthday;
    @Bind(R.id.tv_sex)
    TextView mTvSex;
    @Bind(R.id.et_height)
    EditText mEtHeight;
    @Bind(R.id.et_body_weight)
    EditText mEtBodyWeight;
    @Bind(R.id.tv_measure_title)
    TextView mTvMeasureTitle;
    @Bind(R.id.tv_measure_data)
    TextView mTvMeasureData;
    @Bind(R.id.tv_unit)
    TextView mTvUnit;
    @Bind(R.id.tv_go_measure)
    TextView mTvGoMeasure;
    @Bind(R.id.id_flowlayout)
    TagFlowLayout mFlowLayout;
    @Bind(R.id.btn_commit)
    Button mBtnCommit;

    @Bind(R.id.titlebar_title_tv)
    TextView mTitlebarTitleTv;
    @Bind(R.id.tv_physique)
    TextView mTvPhysique;
    @Bind(R.id.tv_go_assess)
    TextView mTvGoAssess;
    @Bind(R.id.rb_stage1)
    RadioButton mRbStage1;
    @Bind(R.id.rb_stage2)
    RadioButton mRbStage2;
    @Bind(R.id.rb_stage3)
    RadioButton mRbStage3;

    private List<String> mVals;
    private LayoutInflater mInflater;

    private static final int BLOOD_PRESSURE = 1;
    private static final int BLOOD_SUGAR = 2;
    private static final String TYPE_KEY = "type";
    private static final String SEX_RESULT_KEY = "sex_result";
    private static final String SEX_CALL_BACK_KEY = "sex_call_back_key";
    private static final String ASSESS_CALL_BACK_KEY = "assess_call_back_key";
    private static final String ASSESS_RESULT_KEY = "assess_result";
    private static final String DEVICE_TYPE_BLOODPRESSURE = "blood";
    private static final String DEVICE_TYPE_BLOODSUGAR = "bloodsugar";
    private static final int SEX_REQUEST_CODE = 10;
    private static final int ASSESS_REQUEST_CODE = 11;//去评估
    private int mType;
    private String mHigh = "";
    private String mLow = "";
    private String mHeartrate = "";
    private String mBloodsugar = "";
    private boolean isUpdateSex;
    private boolean isManual; //是否手动输入
    private String mBirthday = "";
    private String mHeight = "";
    private String mWeight = "";
    private String mRname = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_prevention_blood_pressure);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        initView();
        initListener();
    }

    private void initView() {
        provider.getUserKeyti();
        mType = getIntent().getIntExtra(TYPE_KEY,1);
        mTvGoMeasure.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        mTvGoMeasure.getPaint().setAntiAlias(true);
        mTvGoAssess.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        mTvGoAssess.getPaint().setAntiAlias(true);

        mInflater = (LayoutInflater) (getParent() != null ? this.getParent() : this).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mVals = new ArrayList<>();
        //高血压这里是糖尿病，糖尿病这里是高血压
        if(mType == BLOOD_PRESSURE){
            initPressRange();
            showBloodPressureView();
            mVals.add("糖尿病");
        }else if(mType == BLOOD_SUGAR){
            initSugarRange();
            showBloodSugarView();
            mVals.add("高血压");
        }


        mVals.add("肾盂肾炎");
        mVals.add("血脂异常");
        mVals.add("肾病综合征");
        mVals.add("脑血管病后遗症");
        mVals.add("颈椎病");
        mVals.add("冠心病");
        mVals.add("月经不调");
        mVals.add("骨质疏松");
        mVals.add("性肾小球肾炎");
        mVals.add("便秘");
        mVals.add("失眠");
        mVals.add("肥胖");
        mVals.add("原发性肾小球肾炎");
        mVals.add("慢性阻塞性肺疾病");
        mFlowLayout.setAdapter(new TagAdapter<String>(mVals) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.flow_layout_tag,
                        mFlowLayout, false);
                tv.setText(s);
                return tv;
            }
        });
    }

    private void initListener() {
        mTvGoMeasure.setOnClickListener(this);
        mTvGoAssess.setOnClickListener(this);
        mTvBirthday.setOnClickListener(this);
        mTvSex.setOnClickListener(this);
        mBtnCommit.setOnClickListener(this);
        mTvMeasureData.setOnClickListener(this);
        mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                //此代码可以实现单选逻辑
//                TagView tagView = (TagView) view.getParent();
//                for(int i=0;i<mFlowLayout.getChildCount();i++){
//                    if(tagView.isChecked()){
//                        TagView t = (TagView) mFlowLayout.getChildAt(i);
//                        if(t == tagView){
//                            continue;
//                        }else{
//                            t.setChecked(false);
//                        }
//                    }
//                }
//                Toast.makeText(PreventionBloodPressureActivity.this, mVals.get(position), Toast.LENGTH_SHORT).show();
                return true;
            }
        });

        mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
//                setTitle("choose:" + selectPosSet.toString());
            }
        });

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        //当测量完血压或者血糖的时候重新请求最近一次测量的数据
        if(mType == BLOOD_PRESSURE) {
            provider.getUserKeyti();
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_go_measure:
                isManual = false;
                Bundle bundle = new Bundle();
                if(mType == BLOOD_PRESSURE){
                    //跳到血压数据
                    bundle.putString(Constants.DEVICE_TYPE, DEVICE_TYPE_BLOODPRESSURE);
                    ActivityUtils.showActivity(this, BloodPressureActivity.class, bundle);
                }else if(mType == BLOOD_SUGAR){
                    //跳到血糖数据
                    bundle.putString(Constants.DEVICE_TYPE, DEVICE_TYPE_BLOODSUGAR);
                    ActivityUtils.showActivity(this, BloodSugarDataActivity.class, bundle);
                }
                break;
            case R.id.tv_go_assess:
                //体质辨识  跳转到33道题
                Bundle bundle1 = new Bundle();
                bundle1.putString("evalFlag", "chinesemedicine");
                bundle1.putString("title", "中医九种体质判定");
                bundle1.putBoolean(ASSESS_CALL_BACK_KEY,true);
                ActivityUtils.showActivityForResult(this, EvaluationActivity.class, bundle1, ASSESS_REQUEST_CODE);
                break;
            case R.id.tv_birthday:
                showDataPicker();
                break;
            case R.id.tv_sex:
                mBirthday = mTvBirthday.getText().toString();
                mHeight = mEtHeight.getText().toString();
                mWeight = mEtBodyWeight.getText().toString();
                mRname = mEtName.getText().toString();
                Intent intent = new Intent(this,RegisterNickActivity.class);
                intent.putExtra(SEX_CALL_BACK_KEY,true);
                intent.putExtra("type", "1");
                intent.putExtra("check_sex", mTvSex.getText().toString());
                startActivityForResult(intent,SEX_REQUEST_CODE);
                break;
            case R.id.btn_commit:
                commitData();
                break;
            case R.id.tv_measure_data:
                if(mType == BLOOD_PRESSURE){
                    showManuallyAddPressData();
                }else if(mType == BLOOD_SUGAR){
                    showManuallyAddSugarData();
                }
                break;
        }
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        if(Act.Flag.FLAG_GET_USER_KEYTI.equals(actionName)){
            Gson gson = new MyGsonBuilder().createGson();
            UserKeyti data = gson.fromJson((String)object, UserKeyti.class);
            setDataToView(data);
            if(mType == BLOOD_PRESSURE){

                if(isManual){
                    mTvMeasureData.setText(mHigh+"/"+mLow);
                    return;
                }

                mHigh = data.getHigh();
                mLow = data.getLow();
                mHeartrate = data.getHeartrate();
                if(TextUtils.isEmpty(mHigh)){
                    mTvMeasureData.setText("");
                }else{
                    mTvMeasureData.setText(mHigh+"/"+mLow);
                }
            }else if(mType == BLOOD_SUGAR){

                if(isManual){
                    mTvMeasureData.setText(mBloodsugar);
                    return;
                }
                mBloodsugar = data.getBloodsugar();
                if(TextUtils.isEmpty(mBloodsugar)){
                    mTvMeasureData.setText("");
                }else{
                    mTvMeasureData.setText(mBloodsugar);
                }
            }
        }

        if(Act.Flag.FLAG_KE_TI_BAO_MING.equals(actionName)){
            KetiSignUpSuccessDialog dialog = new KetiSignUpSuccessDialog(this);
            dialog.show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == SEX_REQUEST_CODE){
            isUpdateSex = true;
            if(data != null) {
                String sexCode = data.getStringExtra(SEX_RESULT_KEY);
                mTvSex.setText(Util.getSex(sexCode));
            }
        }

        if(requestCode == ASSESS_REQUEST_CODE){
            if(data != null) {
                String assessResult = data.getStringExtra(ASSESS_RESULT_KEY);
                mTvPhysique.setText(assessResult);
                mTvPhysique.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void handleActionError(String actionName, String response, VolleyError error) {
        super.handleActionError(actionName, response, error);
    }

    private void showBloodPressureView() {
        TextUtilTools.setTextFromHtml(mRbStage1,"已患有高血压病<br> <font color='#989898'>（经医生确诊）</font>");
        TextUtilTools.setTextFromHtml(mRbStage2,"临界高血压<br> <font color='#989898'>（收缩压120~139/舒张压80~89mmHg）</font>");
        TextUtilTools.setTextFromHtml(mRbStage3,"高血压高危<br> <font color='#989898'>（符合以下条件之一：1、BMI>24；2、男性腰围≥90cm，女性腰围≥85cm；3、每日饮白酒≥2两；4、每日摄盐量>6克（一个去掉胶垫的啤酒瓶盖可盛放6克盐）；5、一级亲属（父母、子女、同父母兄弟姐妹）患有高血压；6、男性≥55岁，绝经后的女性；7、长期过度精神紧张）</font>");
        mTitlebarTitleTv.setText("高血压智慧防控计划");
        mTvMeasureTitle.setText("最近一次测量的血压值：");
        mTvMeasureData.setText("");
        mTvUnit.setText("mmHg");
    }

    private void showBloodSugarView() {
        TextUtilTools.setTextFromHtml(mRbStage1,"已患2型糖尿病<br> <font color='#989898'>（经医生确诊）</font>");
        TextUtilTools.setTextFromHtml(mRbStage2,"血糖受损期<br> <font color='#989898'>（空腹血糖6.1~6.9mmol/l或餐后2小时7.8~11mmol/l）</font>");
        TextUtilTools.setTextFromHtml(mRbStage3,"糖尿病高危因素<br> <font color='#989898'>（符合以下条件之一：1、年龄≥40岁； 2、BMI>24；3、男性腰围≥90cm，女性腰围≥85cm；4、长期静坐生活方式；5、一级亲属（父母、子女、同父母兄弟姐妹）中有2型糖尿病患者；6、高血压，血压≥140/90mmhg；7、血脂异常（HDL-C≤0.91mmol/l及TG≥2.22mmol/l）或正在接受调脂治疗；8、动脉粥样硬化性心脑血管病的患者；9、有一过性类固醇糖尿病病史者；10、多囊卵巢综合征患者；11、长期接受抗精神药物和（或）抗抑郁药物患者）</font>");
        mTitlebarTitleTv.setText("糖尿病智慧防控计划");
        mTvMeasureTitle.setText("最近一次测量的血糖值：");
        mTvMeasureData.setText("");
        mTvUnit.setText("mmol/L");
    }

    private void showDataPicker(){
        DatePicker mPicker = new DatePicker(this);
        mPicker.setRange(Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.YEAR)+1);
        mPicker.setOffset(1);
        mPicker.setSubmitTextColor(getResources().getColor(R.color.theme_color));
        final int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        final int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;
        final int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
        mPicker.setSelectedItem(currentYear, currentMonth, currentDay);
        mPicker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
            @Override
            public void onDatePicked(String year, String month, String day) {
                mTvBirthday.setText(year+"-"+month+"-"+day);
            }
        });
        mPicker.show();
    }

    private void setDataToView(UserKeyti data){
        if(data == null){
            return;
        }
        if(!isUpdateSex) {
            enableFromEmpty(Util.getSexEmpty(data.getSex()), mTvSex);
        }
        if(TextUtils.isEmpty(data.getEval())){
            mTvPhysique.setText("未评估");
        }else{
            mTvPhysique.setText(data.getEval());
        }

        if(!TextUtils.isEmpty(mRname)){
            mEtName.setText(mRname);
        }else{
            enableFromEmpty(data.getRname(),mEtName);
        }

        if(!TextUtils.isEmpty(mBirthday)){
            mTvBirthday.setText(mBirthday);
        }else{
            enableFromEmpty(data.getBirthday(),mTvBirthday);
        }

        if(!TextUtils.isEmpty(mHeight)){
            mEtHeight.setText(mHeight);
        }else{
            enableFromEmpty(data.getHeight(),mEtHeight);
        }

        if(!TextUtils.isEmpty(mWeight)){
            mEtBodyWeight.setText(mWeight);
        }else{
            enableFromEmpty(data.getWeight(),mEtBodyWeight);
        }

        //新注册的用户默认值为0
        if("0".equals(data.getHeight()) && TextUtils.isEmpty(mHeight)){
            mEtHeight.setText("");
            mEtHeight.setEnabled(true);
        }

        if("0".equals(data.getWeight()) && TextUtils.isEmpty(mWeight)){
            mEtBodyWeight.setText("");
            mEtBodyWeight.setEnabled(true);
        }

    }

    private void commitData(){
        mBirthday = mTvBirthday.getText().toString();
        mHeight = mEtHeight.getText().toString();
        mWeight = mEtBodyWeight.getText().toString();
        mRname = mEtName.getText().toString();
        String sex = "";
        if("男".equals(mTvSex.getText().toString())){
            sex = "1";
        }else if("女".equals(mTvSex.getText().toString())){
            sex = "2";
        }

        if(TextUtils.isEmpty(mBirthday) || TextUtils.isEmpty(mHeight) || TextUtils.isEmpty(mWeight) || TextUtils.isEmpty(mRname) || TextUtils.isEmpty(sex)){
            showToast("请补全个人基本信息");
            return;
        }

        String levels = getLevel();//1  2  3
        if(TextUtils.isEmpty(levels)){
            showToast("请选择您目前的疾病阶段");
            return;
        }
        String eval = mTvPhysique.getText().toString();
        if(TextUtils.isEmpty(eval)){
            showToast("请完成体质辨识评估");
            return;
        }

        String type = "";
        if(mType == BLOOD_PRESSURE){
            type = "blood";
            if(TextUtils.isEmpty(mHigh) || TextUtils.isEmpty(mLow)){
                showToast("请填写最近一次测量的血压值");
                return;
            }
        }else if(mType == BLOOD_SUGAR){
            type = "bloodsugar";
            if(TextUtils.isEmpty(mBloodsugar)){
                showToast("请填写最近一次测量的血糖值");
                return;
            }
        }

        Set<Integer> set = mFlowLayout.getSelectedList();
        StringBuilder sb = new StringBuilder();
        for (Integer integer : set) {
            sb.append(mVals.get(integer)+",");
        }
        String sicks = sb.toString();

        provider.ketiBaoming(mBirthday, mBloodsugar,eval, mHeartrate, mHeight, mHigh,levels, mLow, mRname,sex,sicks,type, mWeight);
    }

    /**
     * 根据属性是否为空决定控件是否可用
     */
    private void enableFromEmpty(String attr,TextView et){
        if(TextUtils.isEmpty(attr)){
            et.setEnabled(true);
            et.setText("");
        }else{
            et.setEnabled(false);
            et.setText(attr);
        }
    }

    private String getLevel(){
        if(mRbStage1.isChecked()){
            return "1";
        }else if(mRbStage2.isChecked()){
            return "2";
        }else if(mRbStage3.isChecked()){
            return "3";
        }else{
            return "";
        }
    }


    /**
     * 高压 低压 心率 范围&所选值
     */
    private String[] high_pressure_range = new String[160];
    private String[] low_pressure_range = new String[80];
    private String[] heart_rate_range = new String[80];
    private String high_pressure_chosen = "";
    private String low_pressure_chosen = "";
    private String heart_rate_chosen = "";

    /**
     * 手动输入血压
     */
    private void showManuallyAddPressData() {
        isManual = true;
        high_pressure_chosen = "120"; //默认120
        low_pressure_chosen = "80";   //默认80
        heart_rate_chosen = "70";     //默认70

        View outerView = LayoutInflater.from(this).inflate(R.layout.wheel_view_blood_pressure, null);
        WheelView wv_high = (WheelView) outerView.findViewById(R.id.wheel_view_high_pressure);
        WheelView wv_low = (WheelView) outerView.findViewById(R.id.wheel_view_low_pressure);
        WheelView wv_heart = (WheelView) outerView.findViewById(R.id.wheel_view_heart_rate);

        wv_high.setOffset(1);
        wv_low.setOffset(1);
        wv_heart.setOffset(1);
        wv_high.setItems(Arrays.asList(high_pressure_range));
        wv_low.setItems(Arrays.asList(low_pressure_range));
        wv_heart.setItems(Arrays.asList(heart_rate_range));
        wv_high.setSeletion(40);
        wv_low.setSeletion(low_pressure_range.length / 2);
        wv_heart.setSeletion(heart_rate_range.length / 2);
        wv_high.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                high_pressure_chosen = item;
            }
        });

        wv_low.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                low_pressure_chosen = item;
            }
        });

        wv_heart.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                heart_rate_chosen = item;
            }
        });

        new AlertDialog.Builder(this)
                .setTitle("请选择")
                .setView(outerView)
                .setNegativeButton("取消", null)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mTvMeasureData.setText(high_pressure_chosen+"/"+low_pressure_chosen);
                        mLow = low_pressure_chosen;
                        mHigh = high_pressure_chosen;
                        mHeartrate = heart_rate_chosen;

                    }
                })
                .show();
    }

    /**
     * 血糖范围 glucose_range ,血糖时间 time_range
     * 测量时间 measured_time  默认午餐后 5
     * 测量值 glucose_value   默认6.0
     */
    private String[] glucose_range = new String[120];
    private String[] time_range = {"凌晨", "早餐前", "早餐后", "午餐前", "午餐后", "晚餐前", "晚餐后", "睡前"};
    private int measured_time = 5;
    private String glucose_value = "6.0";

    /**
     * 手动添加血糖数据
     */
    private void showManuallyAddSugarData() {
        isManual = true;
        //初始化血糖范围 2.0~9.9

        measured_time = 5;//默认午餐后
        glucose_value = "8.0";//默认6.0

        View outerView = LayoutInflater.from(this).inflate(R.layout.wheel_view_blood_sugar, null);
        WheelView wv_time = (WheelView) outerView.findViewById(R.id.wheel_view_measured_time);
        WheelView wv_value = (WheelView) outerView.findViewById(R.id.wheel_view_glucose_value);

        wv_time.setOffset(1);
        wv_time.setItems(Arrays.asList(time_range));
        wv_time.setSeletion(time_range.length / 2);
        wv_time.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                measured_time = selectedIndex;
            }
        });

        wv_value.setOffset(1);
        wv_value.setItems(Arrays.asList(glucose_range));
        wv_value.setSeletion(20);
        wv_value.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                glucose_value = item;
            }
        });
        new AlertDialog.Builder(this)
                .setTitle("请选择")
                .setView(outerView)
                .setNegativeButton("取消", null)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mBloodsugar = glucose_value;
                        mTvMeasureData.setText(glucose_value);
                    }
                })
                .show();
    }

    @Subscribe(threadMode= ThreadMode.MAIN,sticky = true)
    public void refreshBloodSugar(SugarEvent event){
        mBloodsugar = event.getSugarData();
        if(TextUtils.isEmpty(mBloodsugar)){
            mTvMeasureData.setText("");
        }else{
            mTvMeasureData.setText(mBloodsugar);
        }
    }

    private void initPressRange(){
        for (int i = 0; i < 160; i++) {
            high_pressure_range[i] = i + 80 + "";
            if (i < 80) {
                low_pressure_range[i] = i + 40 + "";
                heart_rate_range[i] = i + 30 + "";
            }
        }
    }

    private void initSugarRange(){
        for (int i = 4; i < 16; i++) {
            for (int j = 0; j < 10; j++) {
                glucose_range[(i-4) * 10 + j] = i + 2 + "." + j;
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
